﻿using MJTop_WebService.Core;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Security;

namespace MJTop_WebService.Controllers
{

    public class LoginController : ApiController
    {
        [HttpGet]
        public string Index(string account, string password)
        {

            if (account.Equals("Admin", StringComparison.OrdinalIgnoreCase) && password.Equals("123456", StringComparison.OrdinalIgnoreCase))
            {
                FormsAuthenticationTicket ticketObject = new FormsAuthenticationTicket(0, account, DateTime.Now,
                            DateTime.Now.AddSeconds(10), true, string.Format("{0}&{1}", account, password),
                            FormsAuthentication.FormsCookiePath);
                var result = new { Result = true, Ticket = FormsAuthentication.Encrypt(ticketObject) };
                return JsonConvert.SerializeObject(result);
            }
            else
            {
                var result = new { Result = false };
                return JsonConvert.SerializeObject(result);
            }
        }
    }
}
